package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

import static org.jsola.hr.example.SocDispatchEmpLessExample.E_ASSIGN_COMPANY_ID;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_ASSIGN_COMPANY_NAME;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_COMPANY_ID;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_FUND_END_DATE_END;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_FUND_END_DATE_START;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_HAS_RECEIVE;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_HAS_SEND;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_ID_CARD;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_MONTH;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_NAME;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_NO_ERROR;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_PHONE;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_QUIT_DATE_END;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_QUIT_DATE_START;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_REASON_QUIT;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_REMAKE;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_SOC_CITY_ID;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_SOC_CITY_NAME;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_SOC_DISPATCH_ID;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_SOC_END_DATE_END;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_SOC_END_DATE_START;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_SORT;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_STATUS;
import static org.jsola.hr.example.SocDispatchEmpLessExample.E_YEAR;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_ASSIGN_COMPANY_ID;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_ASSIGN_COMPANY_NAME;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_COMPANY_ID;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_FUND_END_DATE_END;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_FUND_END_DATE_START;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_HAS_RECEIVE;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_HAS_SEND;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_ID_CARD;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_MONTH;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_NAME;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_NO_ERROR;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_PHONE;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_QUIT_DATE_END;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_QUIT_DATE_START;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_REASON_QUIT;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_REMAKE;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_SOC_CITY_ID;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_SOC_CITY_NAME;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_SOC_DISPATCH_ID;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_SOC_END_DATE_END;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_SOC_END_DATE_START;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_SORT;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_STATUS;
import static org.jsola.hr.example.SocDispatchEmpLessExample.N_YEAR;

/**
 * 社保派单员工表_减员
 *
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class SocDispatchEmpLessQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = N_SOC_DISPATCH_ID, example = E_SOC_DISPATCH_ID)
    @Length(max = 32)
    private String socDispatchId;

    @ApiParam(value = N_YEAR, example = E_YEAR)
    @Length(max = 12)
    private String year;

    @ApiParam(value = N_MONTH, example = E_MONTH)
    @Length(max = 10)
    private String month;

    @ApiParam(value = N_NAME, example = E_NAME)
    @Length(max = 50)
    private String name;

    @ApiParam(value = N_PHONE, example = E_PHONE)
    @Length(max = 20)
    private String phone;

    @ApiParam(value = N_ID_CARD, example = E_ID_CARD)
    @Length(max = 32)
    private String idCard;

    @ApiParam(value = N_SOC_CITY_NAME, example = E_SOC_CITY_NAME)
    @Length(max = 100)
    private String socCityName;

    @ApiParam(value = N_SOC_CITY_ID, example = E_SOC_CITY_ID)
    private Long socCityId;

    @ApiParam(value = N_ASSIGN_COMPANY_ID, example = E_ASSIGN_COMPANY_ID)
    @Length(max = 32)
    private String assignCompanyId;

    @ApiParam(value = N_ASSIGN_COMPANY_NAME, example = E_ASSIGN_COMPANY_NAME)
    @Length(max = 100)
    private String assignCompanyName;

    /**
     * 社保停缴时间查询范围
     */
    @ApiParam(value = N_SOC_END_DATE_START, example = E_SOC_END_DATE_START)
    private Date socEndDateStart;
    @ApiParam(value = N_SOC_END_DATE_END, example = E_SOC_END_DATE_END)
    private Date socEndDateEnd;


    /**
     * 公积金停缴时间查询范围
     */
    @ApiParam(value = N_FUND_END_DATE_START, example = E_FUND_END_DATE_START)
    private Date fundEndDateStart;
    @ApiParam(value = N_FUND_END_DATE_END, example = E_FUND_END_DATE_END)
    private Date fundEndDateEnd;


    /**
     * 离职时间查询范围
     */
    @ApiParam(value = N_QUIT_DATE_START, example = E_QUIT_DATE_START)
    private Date quitDateStart;
    @ApiParam(value = N_QUIT_DATE_END, example = E_QUIT_DATE_END)
    private Date quitDateEnd;


    @ApiParam(value = N_REASON_QUIT, example = E_REASON_QUIT)
    @Length(max = 2147483647)
    private String reasonQuit;

    @ApiParam(value = N_REMAKE, example = E_REMAKE)
    @Length(max = 2147483647)
    private String remake;

    @ApiParam(value = N_STATUS, example = E_STATUS)
    private Integer status;

    @ApiParam(value = N_HAS_SEND, example = E_HAS_SEND)
    private Boolean hasSend;

    @ApiParam(value = N_HAS_RECEIVE, example = E_HAS_RECEIVE)
    private Boolean hasReceive;

    @ApiParam(value = N_NO_ERROR, example = E_NO_ERROR)
    private Boolean noError;

    @ApiParam(value = N_COMPANY_ID, example = E_COMPANY_ID)
    @Length(max = 32)
    private String companyId;

    @ApiParam(value = N_SORT, example = E_SORT)
    private Integer sort;



    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public SocDispatchEmpLessQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

}

